package com.geostart.constructionland.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geostar.constructionland.common.entity.lockInfo.JsydLockInfo;
import com.geostar.constructionland.common.entity.response.ExtJsAjaxResponse;
import com.geostart.constructionland.system.mapper.JsydLockInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * @author chengan
 * @description 建设用地锁信息接口
 */
@Controller
@RequestMapping(path = "/jsydlock")
public class JsydLockInfoController {

    @Autowired
    JsydLockInfoMapper jsydLockInfoMapper;


    @GetMapping(path = "/profile")
    public String index() {
        return "profile/lockInfo_profile";
    }

    @PostMapping(path = "/lockInfos")
    @ResponseBody
    public ExtJsAjaxResponse listLockInfo(@NotBlank(message = "页码不能为空")  @RequestParam(value = "page") int pageNo,
                                          @NotBlank(message = "每页数量不能为空") @RequestParam(value = "limit") int pageNum,
                                          String query_ajid,
                                          String query_xmmc) {
        Page page = new Page(pageNo,pageNum);
        QueryWrapper<JsydLockInfo> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(query_ajid)){
            queryWrapper.eq("ajid",query_ajid);
        }
        if(!StringUtils.isEmpty(query_xmmc)){
            queryWrapper.like("xmmc",query_xmmc);
        }
        queryWrapper.orderByDesc("lock_time");
        IPage<JsydLockInfo> myPage = jsydLockInfoMapper.selectPageJsydLock(page, queryWrapper);
        return ExtJsAjaxResponse.createBySuccess(myPage);
    }
}
